<template>
	<view>
		<!-- 状态栏 -->
		<view class="statusBar" :style="'height:'+statusBarHeight+'px'"></view>
		<view class="myheader padding-sm  flex justify-between">
			<view class="font-sub-title">
				<text class="cuIcon-back margin-right-ssm" @click="back()"></text>
				危险心率告警
			</view>
			<text class="font-sub-title" @click="save">保存</text>
		</view>
		<view class="cu-list menu">
			<view class="cu-item">
				<view class="content">
					危险心率告警
				</view>
				<view class="action">
					<switch class="blue" @change="open" :class="isopen?'checked':''" :checked="isopen"></switch>
				</view>
			</view>
			<view class="cu-item arrow">
				<view class="content">
					告警阈值
				</view>
				<view class="action text-gray">
					<picker mode="selector" :range="heartList" :value="heartIndex" @change="bindHeartChange">
						<view>{{heartList[heartIndex]}}</view>
					</picker>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const bandSDK = uni.requireNativePlugin('BandSDK')
	var that;
	export default {
		data() {
			return {
				statusBarHeight: Vue.prototype.StatusBar,
				isopen:uni.getStorageSync("heartAlarmOpen")||false,
				heartList:['100','110','120','130','140','150'],
				heartIndex:uni.getStorageSync('heartAlarmIndex')||0,
			}
		},
		onLoad(){
			that = this;
		},
		methods: {
			back(){
				uni.navigateBack();
			},
			open(e){
				this.isopen = e.target.value
			},
			bindHeartChange(e){
				this.heartIndex = e.target.value
			},
			save(){
				var on = this.isopen?'1':'0'
				bandSDK.settingHeartAlarm({
					on:on,
					highHeart:that.heartList[that.heartIndex],
					lowHeart:30
				},res=>{
					if(res=='success'){
						uni.setStorageSync("heartAlarmOpen",that.isopen)
						uni.setStorageSync("heartAlarmIndex",that.heartIndex)
						uni.showToast({
							title:"保存成功"
						})
					}
				})
			}
		}
	}
</script>

<style>

</style>
